package com.qiangesoft.im.exception;

import com.qiangesoft.im.exception.result.ExceptionResultHandler;
import com.qiangesoft.im.exception.result.ResultMessageEnum;

/**
 * 异常基类
 *
 * @author qiangesoft
 * @date 2023-09-18
 */
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    public int code;

    /**
     * 错误提示
     */
    public String message;

    /**
     * 空构造方法，避免反序列化问题
     */
    public BaseException() {
    }

    public BaseException(String message) {
        this.code = ResultMessageEnum.INTERNAL_SERVER_ERROR.getCode();
        this.message = message;
    }

    public BaseException(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public BaseException(ExceptionResultHandler exceptionAdvice) {
        this.code = exceptionAdvice.getCode();
        this.message = exceptionAdvice.getMessage();
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

}